import { Component, OnInit } from '@angular/core';
import {Vehicle} from "../../model/vehicle";
import {Http} from "@angular/http";
import {CamManageService} from "../../service/cam-manage.service";
import MTSConstants from "../../config/config";
import {SingleOpenWinService} from "../../service/single-open-win.service";

@Component({
  selector: 'app-vehicle-table',
  templateUrl: './vehicle-table.component.html',
  styleUrls: ['./vehicle-table.component.css']
})
export class VehicleTableComponent implements OnInit {

  //选择车辆分页
  _current = 1;
  _pageSize = 10;
  _total = 1;
  _dataSet = [];
  queryName = "";
  queryCapacity = "";

  //选择框
  _displayData: Array<any> = [];
  selected:any; //选中车辆
  source:string="";  //判断开窗来源

  constructor(
    private http: Http,
    private camManageService: CamManageService,
    private singleOpenWinService:SingleOpenWinService
  ) { }

  ngOnInit() {
    this.getDatas();
  }

  refreshData(reset = false) {
    if (reset) {
      this._current = 1;
    }
    // this._allChecked = false;
    this.getDatas();
  };

  _displayDataChange($event) {
    this._displayData = $event;
  };

  getDatas(){
    this.camManageService.getVehiclesPageInfo(this._current,this._pageSize,this.queryName,this.queryCapacity).then(res=>{
      this._dataSet = res.list;
      this._total = res.total;
      this._displayData = res.list;
    });
  }

  search() {
    this.queryName = $('#vehicleName').val() as string;
    this.queryCapacity = $('#capacity').val() as string;
    this.getDatas();
  }

  getVehicleInfo(data){
    this.selected = data;
    this.singleOpenWinService.vehicleChange.emit(this.source);
  }
}
